import plotly.graph_objects as go
import pandas as pd


def print_map(source, title1, title2, data, saveName):
    df = pd.read_excel(source, sheet_name='1')

    fig = go.Figure(data=go.Choropleth(
        locations=df['code'],  # 设置位置，各州的编号（缩写）
        z=df[data].astype(float),  # 设置填充色数据
        locationmode='USA-states',  # 设置国家名称
        colorscale='purples',  # 图例颜色
        colorbar_title=title2,  # 图例标题
    ))

    fig.update_layout(
        title_text=title1,  # 地图标题
        geo_scope='usa',  # 设置地图的范围为美国
        # scope可选有"world"，"usa"，"europe"，"asia"，"africa"，"north america"，"south america"
    )

    # 将地图导出为html文件
    fig.write_html(saveName)
